package com.example.send.controller;

import com.example.send.config.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RabbitmqSendController {

    Logger logger = LoggerFactory.getLogger(RabbitmqSendController.class);

    @Autowired
    private RabbitTemplate rabbitTemplate;


    @RequestMapping("/sendQueue")
    public void sendQueue(String id){
        logger.info(id);
        rabbitTemplate.convertAndSend(RabbitmqPointToPointConfig.QUEUE_WORK, id);
    }

    @RequestMapping("/sendFanout")
    public void sendFanout(String id){
        logger.info(id);
        rabbitTemplate.convertAndSend(RabbitmqFanoutConfig.FANOUT_EXCHANGE, id);
    }

    @RequestMapping("/sendTopic")
    public void sendTopic(String id){
        logger.info(id);
        rabbitTemplate.convertAndSend(RabbitmqTopicConfig.TOPIC_EXCHANGE,"topic.message", id);
    }

    @RequestMapping("/sendDirect")
    public void sendDirect(String id){
        logger.info(id);
        rabbitTemplate.convertAndSend(RabbitmqDirectConfig.DIRECT_EXCHANGE,RabbitmqDirectConfig.DIRECT_QUEUE_2, id);
    }


    @RequestMapping("/sendDelay/{path}")
    public void sendDelay(String id, @PathVariable String path) {
        logger.info(id);
        if (path.equals("a")) {
            rabbitTemplate.convertAndSend(RabbitmqDelayConfig.BUSINESS_EXCHANGE_NAME, RabbitmqDelayConfig.BUSINESS_QUEUE_A_NAME, id);
        } else {
            rabbitTemplate.convertAndSend(RabbitmqDelayConfig.BUSINESS_EXCHANGE_NAME, RabbitmqDelayConfig.BUSINESS_QUEUE_B_NAME, id);
        }
    }


}
